package com.sservice.web.controller.pc;

import com.sservice.common.SameUrlData;
import com.sservice.model.vo.SaleCommissionVo;
import com.sservice.service.service.ISaleCommissionService;
import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.entity.dto.Pagination;
import com.sservice.model.entity.SaleCommission;
import com.sservice.banfu.e.SalePerson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/salecommission")
public class SaleCommissionPcController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ISaleCommissionService depService;


    /**
     * @param arg
     * @return
     */
    @SameUrlData
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public BaseResult<Integer> update(SaleCommission arg) {
        int service_res = depService.updateByPrimaryKeySelective(arg);
        BaseResult<Integer> res = new BaseResult<Integer>(true, service_res);
        return res;
    }

    /***
     * 分页查询
     * @param arg
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ListResult query(SaleCommissionVo arg, HttpSession session) {
        SalePerson sp = (SalePerson) session.getAttribute("current");
        ListResult res = null;
        if (sp != null) {
            arg.setSaleId(String.valueOf(sp.getId()));
            List<SaleCommission> list = depService.queryByPage(arg);
            int total = depService.queryCount(arg);
            Pagination page = new Pagination(arg.getPage(), total, arg.getSize());
            res = new ListResult(true, list);
            res.setPage(page);
        } else {
            res = new ListResult(false, "未登录!", 401);
        }

        return res;
    }
}
